﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Security.Authentication;
public partial class CreateBook : System.Web.UI.Page
{
    string connString = ConfigurationManager.ConnectionStrings["bookStoreConnectionString"].ConnectionString;
    string sql_insert = "INSERT INTO Books VALUES(@name, @author)";
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    int Create(Book book)
    {
        SqlConnection con = new SqlConnection(connString);
        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Parameters.Add("@name", SqlDbType.VarChar);
        cmd.Parameters.Add("@author", SqlDbType.VarChar);
        //
        cmd.Parameters["@name"].Value = book.Name;
        cmd.Parameters["@author"].Value = book.Author; ;
        //
        return cmd.ExecuteNonQuery();
    }
    protected void btnCreate_Click(object sender, EventArgs e)
    {
        Book book = new Book
        {
            Author = txtAuthor.Text.Trim(),
            Name = txtName.Text.Trim()
        };
        Create(book);
    }
}